package com.k.base.jdk.stream.liststring;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author kivil
 */
public class ListStringTest {
    private static List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
    private static List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
    private static List<Integer> integers = Arrays.asList(1,2,13,4,15,6,17,8,19);

    /**
     * list string test
     */
    private static void listStringTest(){
        long count = 0L;
        List<String> filtered;
        count = strings.stream().filter(string->string.isEmpty()).count();
        long count1 = strings.stream().filter(String::isEmpty).count();
        System.out.println("Empty Strings: " + count);
        System.out.println("Empty Strings: "+ count1);

        count = strings.stream().filter(string -> string.length() == 3).count();
        System.out.println("Strings of length 3: " + count);

        filtered = strings.stream().filter(string ->!string.isEmpty()).collect(Collectors.toList());
        System.out.println("Filtered List: " + filtered);

        String mergedString = strings.stream().filter(string ->!string.isEmpty()).collect(Collectors.joining(", "));
        System.out.println("Merged String: " + mergedString);
    }

    /**
     * list Integer test
     */
    private static void listIntegerTest(){
        List newList = numbers.stream().map( i ->i*i).distinct().collect(Collectors.toList());
        IntSummaryStatistics stats = integers.stream().mapToInt((x) ->x).summaryStatistics();
        System.out.println("new list:" + newList);
        System.out.println("Highest number in List : " + stats.getMax());
        System.out.println("Lowest number in List : " + stats.getMin());
        System.out.println("Sum of all numbers : " + stats.getSum());
        System.out.println("Average of all numbers : " + stats.getAverage());
    }

    public static void main(String[] args) {
        listIntegerTest();

    }
}
